﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ComeSeeThis_MVC2.Models
{
    public class FeedbackRepository
    {
        private readonly ComeSeeThisDBEntities context = new ComeSeeThisDBEntities();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="read">1 = All, 2 = Read, 3 = Not Read</param>
        /// <returns></returns>
        public IQueryable<Feedback> GetFeedBackList(int read)
        {
            var results = context.Feedbacks.OrderByDescending(x=>x.DateSubmitted);
            switch (read)
            {
                case 2:
                    return results.Where(x => x.FeedbackRead == false);
                case 3:
                    return results.Where(x => x.FeedbackRead == false);
                default:
                    return results;
            }
        }

        public Feedback GetFeedback(int id)
        {
            return context.Feedbacks.FirstOrDefault(x => x.id == id);
        }

        #region Add/Delete

        public void Add(Feedback feedback)
        {
            context.Feedbacks.AddObject(feedback);
        }

        public void Delete(Feedback feedback)
        {
            context.Feedbacks.DeleteObject(feedback);
        }

        #endregion

        #region Persistance

        public void Save()
        {
            context.SaveChanges();
        }

        #endregion

    }
}